package com.xinsoft.controller.device;

import com.xinsoft.common.Response;
import com.xinsoft.entity.dto.CusDeviceDocumentPageParam;
import com.xinsoft.entity.po.CusDocument;
import com.xinsoft.service.CusDocumentService;
import com.xinsoft.validator.ValidatorUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cus/deviceFile")
public class CusDeviceFileController {

    @Resource
    public CusDocumentService cusDocumentService;

    /**
     * 新增
     */
    @PostMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> add(@RequestBody CusDocument cusDocument) {
        // 参数校验
        ValidatorUtils.validateEntity(cusDocument);
        return Response.succeed(cusDocumentService.save(cusDocument));
    }

    /**
     * 获取详情
     */
    @GetMapping("/detail")
    public Response<?> detail(@RequestParam(value = "id", defaultValue = "", required = true) Integer id) {
        return Response.succeed(cusDocumentService.getDocumentDetail(id));
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    @Transactional(rollbackFor = Exception.class)
    public Response<?> del(@RequestBody List<Integer> ids) {
        cusDocumentService.del(ids);
        return Response.succeed();
    }


    /**
     * 分页
     */
    @PostMapping("/pageList")
    public Response<?> pageList(@RequestBody CusDeviceDocumentPageParam cusDeviceDocumentPageParam) {
        return Response.succeed(cusDocumentService.findPageListByParam(cusDeviceDocumentPageParam));
    }
}
